<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class AppCourse extends Model
{
    use HasFactory;
    const STATUS = [0=>'下架',1=>'上架'];
    protected $appends = [
        'status_text'
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    /**
     *  获取状态.
     *
     * @param string $value
     * @return string
     */
    public function getStatusTextAttribute()
    {
        $status = $this->attributes['status'];
        return self::STATUS[$status];
    }

    public function videos()
    {
        return $this->hasMany('App\Models\AppCourseVideo','app_course_id','id')->with('video');
    }

    public function informations()
    {
        return $this->hasMany('App\Models\AppCourseFile','app_course_id','id')->with('information');
    }

    public function order()
    {
        return $this->hasOne('App\Models\AppOrder','product_id','id')->where('pay_status','success')->where('type','course')->select('id','product_id','no','pay_status','user_id');
    }

    public function orders()
    {
        return $this->hasMany('App\Models\AppOrder','product_id','id')->where('type','course')->where('pay_status','success')->select('id','product_id','no','pay_status','user_id');
    }

    

    

}
